package com.zhixi.controller;

import com.zhixi.datasource.UsingDataSource;
import com.zhixi.pojo.Student;
import com.zhixi.service.StudentService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName StudentController
 * @Author zhangzhixi
 * @Description 多数据源切换
 * @Date 2023-02-01 23:17
 * @Version 1.0
 */
@RestController
@RequestMapping("/student")
public class StudentController {
    @Resource
    private StudentService studentService;

    /**
     * 使用db环境1
     * @return 环境1查询数据
     */
    @UsingDataSource("ds1")
    @GetMapping("/getStuToDb1")
    public Student getStudentToDb1() {
        return studentService.getStudentById(1);
    }

    /**
     * 使用db环境2
     * @return 环境2查询数据
     */
    @UsingDataSource("ds2")
    @GetMapping("/getStuToDb2")
    public Student getStudentToDb2() {
        return studentService.getStudentById(1);
    }
}
